<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport"/>
    <meta name="apple-touch-fullscreen" content="yes"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta http-equiv="Cache-Control" content="no-cache"/>
    <link rel="stylesheet" href="__HOME__/css/style.css" type="text/css">
    <title>问券调查</title>
    <script type="text/javascript" src="__HOME__/js/js.js"></script>
    <script type="text/javascript" src="__HOME__/js/jquery-1.11.1.min.js"></script>
</head>
<body>
<form action="__CONTROLLER__/getData" method="post" id="sub_form">
<input type="hidden" name="sid" value="{$result.sid}">
<h1 class="title">{$result.name}</h1>
<p class="wqbz">{$result.desc}</p>
<foreach name="result.quest" item="vo">
    <div class="wenti">
        <p class="went_p">
            <if condition="$vo.isrequired eq 1">
                <span>*</span>
            </if>
            {$vo.questno}.{$vo.question}
        </p>
        <p class="went_b">{$vo.description}</p>
        <if condition="$vo.questiontype eq 1">
            <foreach name="vo.options" item="lo">
                <p class="da">
                      <span class="radio">
                            <input id="redio{$vo.questionid}_{$lo.optionno}" class="{$vo.questionid}" type="radio" name="{$vo.questionid}"
                                   value="{$lo.optionid}"/>
                              <label for="redio{$vo.questionid}_{$lo.optionno}"></label>
                      </span>
                    <span class="xuanx">{$lo.optioncontent}</span>
                </p>
            </foreach>
            <elseif condition="$vo.questiontype eq 2"/>
            <foreach name="vo.options" item="lo">
                <p class="da">
                  <span class="checkbox">
<!--
                      <input id="{$vo.questionid}" type="checkbox" name="{$vo.questionid}[]"
-->
                      <input id="{$vo.questionid}"  type="checkbox" name="{$vo.questionid}[]"
                             value="{$lo.optionid}" />
                      <label for="{$vo.questionid}"></label>
                  </span>
                    <span class="xuanx">{$lo.optioncontent}</span>
                </p>
            </foreach>
            <elseif condition="$vo.questiontype eq 3"/>
            <p class="da">
                <select name="{$vo.questionid}" id="{$vo.questionid}" >
                    <option value="">请选择</option>
                    <foreach name="vo.options" item="lo">
                        <option value="{$lo.optionid}">{$lo.optioncontent}</option>
                    </foreach>
                </select>
            </p>
            <elseif condition="$vo.questiontype eq 4"/>
            <p class="da">
                <input type="text" name="{$vo.questionid}" id="{$vo.questionid}"  class="da_an"/>
            </p>
            <else/>
            <p class="da">
                <textarea name="{$vo.questionid}" id="{$vo.questionid}" ></textarea>
            </p>
        </if>
    </div>
</foreach>
<p class="iphone">
    <span>*</span>手机号： <input type="text" id="iphone" name="iphone" placeholder="请输入手机号"/>
</p>
<p><button class="tijiao" onclick="sub();return false;">提交</button></p>
</form>
<script>
    function sub() {
        var names = '{$require}';
        if(!(names == 'null')){
            var key = 0;
            $.each(JSON.parse(names),function(i,n){
                if(n['type']==1){
                   // var checks = $("."+n['id']).val();
                    var checks = $("input[name="+n["id"]+"]:checked").val();
                    if(checks == undefined){
                        key +=1;
                        var prompt = "必填项不能为空！";
                    };
                }else if(n['type']==2){
                    //var checks = $('input[name="16[\]"\]:checked').val();
                    var checks = $("input[name=\""+n["id"]+"[\]\"]:checked").val();
                    if(checks == undefined){
                        key +=1;
                        var prompt = "必填项不能为空！";
                    }
                }else{
                    var checks = $("#"+n['id']).val();
                    if(checks == ''){
                        key +=1;
                        var prompt = "必填项不能为空！";
                    };
                }
                if(prompt){
                    alert(prompt);
                    return false;
                }
            });
            if(key>=1) return false;
        }

        var iphone = $("#iphone").val();
        var pattern = /^1[34578]\d{9}$/;

        if(!pattern.test(iphone)){
            alert('手机号码格式不正确！');
        }else{
            $('#sub_form').submit();
        }
    }

    var id = '{$result.sid}';
    $.post("__CONTROLLER__/updateAccess",{id:id},function(result){
        console.log(result);
    },"json");
</script>
</body>
</html>
